import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  
  {
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true
  },{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/login/register'),
    hidden: true
  },
  {
    path: '/forgetPwd',
    component: () => import('@/views/login/forgetPwd'),
    hidden: true
  },
  // 素材管理
  {
    path: '/material',
    component: Layout,
    redirect: '/material/teacher',
    meta: {
      title: '菜单管理',
      icon: 'plane'
    },
    children: [{
        path: 'teacher',
        name: 'teacher',
        component: () => import('@/views/material/teacher'),
        meta: {
          title: '讲师信息',
        }
      },
      {
        path: 'spending',
        name: 'spending',
        component: () => import('@/views/material/spending'),
        meta: {
          title: '课程管理',
        }
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
